package com.kabigon.tiny.controller;

import cn.hutool.json.JSONObject;
import cn.xuyanwu.spring.file.storage.FileInfo;
import cn.xuyanwu.spring.file.storage.FileStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class FileController {

    @Autowired
    private FileStorageService fileStorageService;

    /**
     * 上传文件
     */
    @PostMapping(value = {"/upload"})
    public JSONObject upload(MultipartFile file) {
        FileInfo fileInfo = fileStorageService.of(file).upload();
        return new JSONObject(fileInfo);
    }
}